
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 10/28/2015 15:42:34
-- Generated from EDMX file: G:\解决方案\毕业设计\BiYeSheJi\BYSJ.Model\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [BYSH];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_UserQuesting]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[QuestingSet] DROP CONSTRAINT [FK_UserQuesting];
GO
IF OBJECT_ID(N'[dbo].[FK_UserHuiFu]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HuiFuSet] DROP CONSTRAINT [FK_UserHuiFu];
GO
IF OBJECT_ID(N'[dbo].[FK_UserAnswer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AnswerSet] DROP CONSTRAINT [FK_UserAnswer];
GO
IF OBJECT_ID(N'[dbo].[FK_AnswerQuesting]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[QuestingSet] DROP CONSTRAINT [FK_AnswerQuesting];
GO
IF OBJECT_ID(N'[dbo].[FK_QuestingHuiFu]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[HuiFuSet] DROP CONSTRAINT [FK_QuestingHuiFu];
GO
IF OBJECT_ID(N'[dbo].[FK_UserFileMang]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[FileMangSet] DROP CONSTRAINT [FK_UserFileMang];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[QuestingSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[QuestingSet];
GO
IF OBJECT_ID(N'[dbo].[AnswerSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AnswerSet];
GO
IF OBJECT_ID(N'[dbo].[HuiFuSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[HuiFuSet];
GO
IF OBJECT_ID(N'[dbo].[FileMangSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[FileMangSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [PassWord] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [ImagePsth] nvarchar(max)  NULL,
    [CreatTime] datetime  NULL,
    [uptime] datetime  NULL,
    [IsLock] bit  NOT NULL,
    [shenfen] int  NOT NULL
);
GO

-- Creating table 'QuestingSet'
CREATE TABLE [dbo].[QuestingSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [content] nvarchar(max)  NOT NULL,
    [userid] int  NOT NULL,
    [isdel] bit  NOT NULL,
    [answerid] int  NOT NULL,
    [uptime] datetime  NOT NULL,
    [creattime] datetime  NOT NULL
);
GO

-- Creating table 'AnswerSet'
CREATE TABLE [dbo].[AnswerSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [title] nvarchar(max)  NOT NULL,
    [content] nvarchar(max)  NOT NULL,
    [userid] int  NOT NULL,
    [isdel] bit  NOT NULL,
    [uptime] datetime  NOT NULL,
    [creattime] datetime  NOT NULL
);
GO

-- Creating table 'HuiFuSet'
CREATE TABLE [dbo].[HuiFuSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [content] nvarchar(max)  NOT NULL,
    [userid] int  NOT NULL,
    [isdel] bit  NOT NULL,
    [questringid] int  NOT NULL,
    [uptime] datetime  NOT NULL,
    [creattime] datetime  NOT NULL
);
GO

-- Creating table 'FileMangSet'
CREATE TABLE [dbo].[FileMangSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [FileId] int  NOT NULL
);
GO

-- Creating table 'VideoSet'
CREATE TABLE [dbo].[VideoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [name] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'QuestingSet'
ALTER TABLE [dbo].[QuestingSet]
ADD CONSTRAINT [PK_QuestingSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AnswerSet'
ALTER TABLE [dbo].[AnswerSet]
ADD CONSTRAINT [PK_AnswerSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'HuiFuSet'
ALTER TABLE [dbo].[HuiFuSet]
ADD CONSTRAINT [PK_HuiFuSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'FileMangSet'
ALTER TABLE [dbo].[FileMangSet]
ADD CONSTRAINT [PK_FileMangSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'VideoSet'
ALTER TABLE [dbo].[VideoSet]
ADD CONSTRAINT [PK_VideoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [userid] in table 'QuestingSet'
ALTER TABLE [dbo].[QuestingSet]
ADD CONSTRAINT [FK_UserQuesting]
    FOREIGN KEY ([userid])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_UserQuesting'
CREATE INDEX [IX_FK_UserQuesting]
ON [dbo].[QuestingSet]
    ([userid]);
GO

-- Creating foreign key on [userid] in table 'HuiFuSet'
ALTER TABLE [dbo].[HuiFuSet]
ADD CONSTRAINT [FK_UserHuiFu]
    FOREIGN KEY ([userid])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_UserHuiFu'
CREATE INDEX [IX_FK_UserHuiFu]
ON [dbo].[HuiFuSet]
    ([userid]);
GO

-- Creating foreign key on [userid] in table 'AnswerSet'
ALTER TABLE [dbo].[AnswerSet]
ADD CONSTRAINT [FK_UserAnswer]
    FOREIGN KEY ([userid])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_UserAnswer'
CREATE INDEX [IX_FK_UserAnswer]
ON [dbo].[AnswerSet]
    ([userid]);
GO

-- Creating foreign key on [answerid] in table 'QuestingSet'
ALTER TABLE [dbo].[QuestingSet]
ADD CONSTRAINT [FK_AnswerQuesting]
    FOREIGN KEY ([answerid])
    REFERENCES [dbo].[AnswerSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_AnswerQuesting'
CREATE INDEX [IX_FK_AnswerQuesting]
ON [dbo].[QuestingSet]
    ([answerid]);
GO

-- Creating foreign key on [questringid] in table 'HuiFuSet'
ALTER TABLE [dbo].[HuiFuSet]
ADD CONSTRAINT [FK_QuestingHuiFu]
    FOREIGN KEY ([questringid])
    REFERENCES [dbo].[QuestingSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_QuestingHuiFu'
CREATE INDEX [IX_FK_QuestingHuiFu]
ON [dbo].[HuiFuSet]
    ([questringid]);
GO

-- Creating foreign key on [FileId] in table 'FileMangSet'
ALTER TABLE [dbo].[FileMangSet]
ADD CONSTRAINT [FK_UserFileMang]
    FOREIGN KEY ([FileId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_UserFileMang'
CREATE INDEX [IX_FK_UserFileMang]
ON [dbo].[FileMangSet]
    ([FileId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------